package com.gjy.sql.mysql;

import com.gjy.sql.postgre.PostgreUtil;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-08-18 16:23:13
 */
public class MySQLUtil {

    private static final String url;
    private static final String username;
    private static final String password;

    static {
        try {
            InputStream is = PostgreUtil.class.getClassLoader().getResourceAsStream("mysql.properties");
            Properties properties = new Properties();
            properties.load(is);
            Class.forName(properties.getProperty("driver"));
            url = properties.getProperty("url");
            username = properties.getProperty("username");
            password = properties.getProperty("password");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static Connection connection() {
        try {
            return DriverManager.getConnection(url, username, password);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

}
